#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <cassert>

void RotateL(Node* parent)
{
    Node* subR = parent->_right;
    subRL = subR->_left;

    parent->_right = subRL;
    if (subRL)
        subRL->parent = parent;

    Node* ppnode = parent->_parent;

    subR->left = parent;
    parent->_parent = subR;

    if (ppnode == nullptr)
    {
        _root = subR;
        _root->_parent = nullptr;
    }
    else
    {
        if (ppnode->_left == parent)
        {
            ppnode->_left = subR;
        }
        else if (ppnode->_right == parent)
        {
            ppnode->_right = subR;
        }
    }
    ppnode->_bf = subR->_bf = 0;
}

void RotateR(Node* parent)
{
	Node* subL = parent->_left;
	Node* subLR = subLR->_right;

	Node* grand = parent->_parent;
	parent->_left = subRL;

	if (subRL)
		subRL->_parent = parent;

	subL->_right = parent;
	parent->_parent = subL;

	if (grand == nullptr)
	{
		_root = subL;
		subL->_parent = nullptr;
	}
	else
	{
		if (grand->_left == parent)
			grand->_left = subL;
		else
			grand->right = subL;

		subL->_parent = grand;
	}
	parent->_bf = subL->_bf = 0;
}